package org.itboys.core.controller.web.invoice;

import org.itboys.core.entity.mongo.SundayInvoice;
import org.itboys.core.service.mongo.web.SundayInvoiceService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：贾琦磊
 * @Date：2018/12/5
 * @Description：发票
 */
@Controller
@RequestMapping("/sunday/web/invoice")
public class SundayInvoiceController extends BaseController{
    @Autowired
    private SundayInvoiceService invoiceService;
    @RequestMapping("/index")
    public String index(HttpServletRequest request, HttpServletResponse response) {
        return "/sunday/invoice/index";
    }

    @RequestMapping("/select")
    public void select(HttpServletResponse response, HttpServletRequest request) {
        PageResult<SundayInvoice> result = invoiceService.select(request);
        JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
    }

    @RequestMapping("/update")
    public void update(HttpServletRequest request, HttpServletResponse response
            , @RequestParam(value = "id") Long id
            , @RequestParam(value = "status") Integer status
    ) {
        SundayInvoice invoice = new SundayInvoice();
        invoice.setStatus(status);
        invoiceService.updateExceptEmpty(id, invoice);
        ResponseMessage.success();
    }
}
